<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('店铺设置列表')"/>
    <th:block th:include="include :: bootstrap-editable-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="shop-config-form">
                <div class="select-list">
                    <ul>
                        <li>
                            参数名称：<input type="text" name="configName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-table-editable-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('back:shopConfig:edit')}]];
    var prefix = ctx + "back/shopConfig";

    $(function () {
        var options = {
            url: prefix + "/searchList",
            updateUrl: prefix + "/edit/{id}",
            modalName: "店铺设置",
            onEditableSave:onEditableSave,
            columns: [
                {
                    field: 'configId',
                    title: '配置ID'
                },
                {
                    field: 'configName',
                    title: '配置名称'
                },
                {
                    field: 'configValue',
                    title: '配置值',
                    formatter: function (value, row, index) {
                        if($.common.isEmpty(value)){
                            if('核销密码' == row.configName){
                                return '-';
                            }else{
                                return row.systemValue;
                            }
                        }
                        return value;
                    },
                    editable: function(value, row, index) {
                        if (1 == row.configValueType) {
                            return {
                                type: 'select',
                                title: '配置值',
                                source: [{
                                    value: 'Y',
                                    text: "开启"
                                }, {
                                    value: 'N',
                                    text: "关闭"
                                }]
                            }
                        } else if ('核销密码' == row.configName) {
                            return {
                                type: 'text',
                                title: '配置值'
                            }
                        } else {
                            return {
                                type: 'text',
                                title: '配置值',
                                emptytext: "【配置值】不能为空",
                                validate: function (v) {
                                    if ($.trim(v) == '') {
                                        return '【配置值】不能为空!';
                                    }
                                }
                            }
                        }
                    }
                }
            ]
        };
        $.table.init(options);
    });

    function onEditableSave(field, row, oldValue, $el) {
        let updateData = {
            configId:row.configId,
            configValue:row.configValue,
        };
        $.ajax({
            type: 'post',
            url: ctx + "back/shopConfig/edit",
            data: updateData,
            dataType: 'json',
            async: false,
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $.modal.alertSuccess("修改成功");
                } else {
                    $.modal.alertError(result.msg);
                    $.table.refresh();
                }
            }
        });
    }
</script>
</body>
</html>